<?php
require_once 'nehcfrus.php';
require_once 'io.php';
require_once 'html2txt.php';
$html_dir = NEHCFRUS_HOME.'/downloads/html';
$txt_dir  = NEHCFRUS_HOME.'/php/functions';
$d=dir($html_dir);
while (false!==($entry=$d->read())) {
    if (!preg_match("#function\.(.+)\.html#",$entry,$m)) continue;
    $f   = $html_dir.'/'.$entry;
    $c   = file_get_contents($f);
    $txt_file = $txt_dir.'/'.$m[1].'.txt';
    if (!preg_match('#<\/h1[^>]*>(.+)<hr#si',$c,$matches)) {
        echo $entry.'('.strlen($c).')'."\n";
        continue;
    }
    $text = html2txt($matches[1]);
    $tags[]=str_replace('-','_',$m[1]).chr(9).$txt_file.chr(9).'1';
    io::writeFile($txt_file,$text);
}
io::writeFile(NEHCFRUS_HOME.'/php/tags',implode(chr(10),$tags));
?>
